#pragma once

#include <QtCore/QObject.h>
#include "WaveForm.h"

class SampleWindow;

class ISampleWindowListener
{
public:
	virtual void sampleWindowChanged( SampleWindow* /*sampleWindow*/ ) {}
};

class SampleWindow
{
public:
	SampleWindow();
	SampleWindow( const WaveForm* waveForm );
	SampleWindow( const SampleWindow& other );
	const SampleWindow& operator=( const SampleWindow& other );

	const WaveForm*	getWaveForm() const		{ return mWaveForm; }
	int				getPosition() const		{ return mPosition; }
	std::size_t		getWidth() const		{ return mWidth; }

	void			setPosition( int position );
	void			setWidth( std::size_t width );

	void			getSamples( WaveForm::Samples& samples ) const;
	void			getNormalizedSamples( WaveForm::NormalizedSamples& normalizedSamples ) const;

	int				samplePositionToViewPosition( int samplePosition, int viewWidth ) const;
	int				viewPositionToSamplePosition( int viewPosition, int viewWidth ) const;

	void			registerListener( ISampleWindowListener* listener ) { mListeners.push_back( listener ); }


	void			fireChangeEvent();

private:
	void			copyFrom( const SampleWindow& other );

	
	std::vector<ISampleWindowListener*> mListeners;
	const WaveForm*	mWaveForm;
	int				mPosition;
	std::size_t		mWidth;	
};
